#pragma once
#include <base\BV.h>

namespace gc {

	class LBvhLeaves {
	public:
		int *parent;
		int *primIdx;
		int *segLen, *segOffset;
		int *escape;
		uint *morton;
		BV_SOA bv;

		//__host__ __device__ LBvhLeaves() {}
		void malloc(uint size);
		void free();
	};

	class LBvhInteriors {
	public:
		int *parent;
		int *lc, *rc;
		int *rangeL, *rangeR;
		int *escape;
		BV_SOA bv;
		BV_SOA bvR; // bv of right subtree

		//__host__ __device__ LBvhInteriors() {}
		void malloc(uint size);
		void free();
	};

	struct InteriorBuildAid {
		uint *metrics;
		int *visitCount;
		int *leftLeafCount; // height to the leftmost leaf

		//__host__ __device__ InteriorBuildAid() {}
	};

	inline __device__ int isLeaf(const int idx, int *idx_original) {
		if (idx < 0) {
			*idx_original = -idx - 1;
			return 0;
		}
		*idx_original = idx;
		return 1;
	}

	inline __device__ int interiorIdx(const int idx) {
		return -idx - 1;
	}
}